/*
 * MarkSweep.h
 *
 *  Created on: 2011-7-23
 *      Author: Donghan
 */

#ifndef MARKSWEEP_H_
#define MARKSWEEP_H_

#include "HeapBitmap.h"
#include "HeapSource.h"

/* Downward-growing stack for better cache read behavior.
 */
typedef struct {
    /* Lowest address (inclusive)
     */
    const Object **limit;

    /* Current top of the stack (inclusive)
     */
    const Object **top;

    /* Highest address (exclusive)
     */
    const Object **base;
} GcMarkStack;

/* This is declared publicly so that it can be included in gDvm.gcHeap.
 */
typedef struct {
	HeapBitmap *bitmap;
	GcMarkStack stack;
	const char *immuneLimit;
	const void *finger;   // only used while scanning/recursing.
} GcMarkContext;

enum RefType {
    REF_SOFT,
    REF_WEAK,
    REF_PHANTOM,
    REF_WEAKGLOBAL
};

bool dvmHeapBeginMarkStep(void);
void dvmHeapMarkRootSet(void);
void dvmHeapScanMarkedObjects(void);
void dvmHeapHandleReferences(Object *refListHead, enum RefType refType);
void dvmHeapScheduleFinalizations(void);
void dvmHeapFinishMarkStep(void);

void dvmHeapSweepUnmarkedObjects(int *numFreed, size_t *sizeFreed);


#endif /* MARKSWEEP_H_ */
